package com.xlr.excel.util.excel;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import com.xlr.excel.entity.SourseVehicle;
import com.xlr.excel.service.SourseVehicleService;
import com.xlr.excel.util.QueueProduct;
import com.xlr.excel.util.SpringContextUtils;
import lombok.extern.slf4j.Slf4j;

/**
 * @Author: xlr
 * @Date: Created in 上午1:24 2019/3/1
 */
@Slf4j
public class SheetHandlerData extends SheetHandler {


    SourseVehicleService sourseVehicleService;



    List<SourseVehicle> list = new ArrayList <>(  );
    /**
     * @param filePath 文件路径
     * @param collSize 列数量
     */
    public SheetHandlerData(String filePath, Integer collSize,SourseVehicleService sourseVehicleService) {
        super( filePath, collSize );
        this.sourseVehicleService = sourseVehicleService;
    }
    AtomicInteger atomicInteger = new AtomicInteger(  );

    /**
     * 核心处理业务类
     * @param sheetIndex sheet 页
     * @param curRow 行号
     * @param rowList 内容
     */
    @Override
    public void optRows(int sheetIndex, int curRow, List<String> rowList) {
        if(rowList.isEmpty()){
            return;
        }
        QueueProduct.sendQueue(converToBean(rowList));
    }

    public SourseVehicle converToBean(List<String> rowList){
        SourseVehicle sv = new SourseVehicle();
        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss.sss" );
        sv.setYear( rowList.get(0) );
        sv.setSeazon( rowList.get( 1 ) );
        sv.setMonth( rowList.get( 2 ) );
        sv.setPeriod( rowList.get( 3 ) );
        sv.setVin(rowList.get( 4 ));
        sv.setName(rowList.get( 5 ));
        sv.setStatus( Integer.valueOf( rowList.get( 6 ) ) );
        try {
            sv.setCreateAt( sdf.parse( rowList.get( 7 ) ) );
            sv.setUpdateAt( sdf.parse( rowList.get( 8 ) ) );
        } catch (ParseException e) {
            e.printStackTrace();
        }
        sv.setCasa(Integer.valueOf( rowList.get( 9 ) ));
        sv.setStatus2( Integer.valueOf( rowList.get( 10 ) ) );
        return sv;
    }

}
